package com.zkdcloud.repository;

import com.zkdcloud.domain.Category;
import org.jfaster.mango.annotation.DB;
import org.jfaster.mango.annotation.SQL;
import org.jfaster.mango.plugin.page.Page;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 分类dao
 *
 * @author zk
 * @since 2018/5/2
 */
@DB(table = "category")
@Repository
public interface CategoryDao {
    /**
     * 列
     */
    String column = " id,business_id,name,description,icon_url,create_time ";

    /**
     * 插入分类
     *
     * @param category 分类
     */
    @SQL("insert into #table("+column+") values(:id,:businessId,:name,:description,:iconUrl,:createTime)")
    void addCategory(Category category);

    /**
     * 获取分类列表
     *
     * @return list
     */
    @SQL("select " + column + " from #table where business_id = :1")
    List<Category> getAll(String bid);
    /**
     * 获取分类列表
     *
     * @return list
     */
    @SQL("select " + column + " from #table where business_id = :1")
    List<Category> getAll(String bid, Page page);

    /**
     * 根据id获取指定分类
     *
     * @param id id
     * @return category
     */
    @SQL("select " + column + " from #table where id = :1")
    Category getById(String id);

    /**
     * 根据id删除
     *
     * @param id id
     * @return category
     */
    @SQL("delete from #table where id= :1")
    void removeById(String id);

    /**
     * 更新指定分类
     *
     * @param category category
     */
    @SQL("update #table set id = :id " +
            "#if(:name != null) ,name = :name #end" +
            " #if(:description != null), description = :description #end" +
            " #if(:iconUrl != null) ,icon_Url = :iconUrl #end" +
            " where id = :id")
    void update(Category category);
}
